package tests.page;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description: 人员管理页面
 * User: Spider-Man
 * Date: 2025-09-21
 * Time: 18:26
 */
public class PersonnelManagementPage {

    /**
     * 人员列表
     */
    public void personnelListPage() throws IOException {
        WebDriver driver = Utils.createDriver();
        driver.findElement(By.cssSelector("#userList")).click();
        WebElement element = driver.findElement(By.cssSelector("body > div > h2"));
        String expect = element.getText();
        assert expect.equals("人员列表");

        element = driver.findElement(By.cssSelector("body > div > div > table > thead > tr > th:nth-child(1)"));
        expect = element.getText();
        assert expect.equals("人员id");

        element = driver.findElement(By.cssSelector("body > div > div > table > thead > tr > th:nth-child(2)"));
        expect = element.getText();
        assert expect.equals("姓名");

        element = driver.findElement(By.cssSelector("body > div > div > table > thead > tr > th:nth-child(3)"));
        expect = element.getText();
        assert expect.equals("身份");

        Utils.getScreenShot(Thread.currentThread().getName());
    }

    /**
     * 注册普通用户
     */
    public void createPersonnel() throws IOException {
        WebDriver driver = Utils.createDriver();
        driver.findElement(By.cssSelector("#register")).click();
        WebElement element = driver.findElement(By.cssSelector("body > div > h2"));
        String expect = element.getText();
        assert expect.equals("填写注册信息");

        element = driver.findElement(By.cssSelector("#registerForm > div:nth-child(1) > label"));
        expect = element.getText();
        expect.equals("姓名");
        element = driver.findElement(By.cssSelector("#name"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("请输入姓名");

        element = driver.findElement(By.cssSelector("#registerForm > div:nth-child(2) > label"));
        expect = element.getText();
        expect.equals("邮箱");
        element = driver.findElement(By.cssSelector("#mail"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("请输入邮箱");

        element = driver.findElement(By.cssSelector("#registerForm > div:nth-child(3) > label"));
        expect = element.getText();
        expect.equals("手机号");
        element = driver.findElement(By.cssSelector("#phoneNumber"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("请输入手机号");

        element = driver.findElement(By.cssSelector("#registerForm > button"));
        expect = element.getText();
        expect.equals("注册");

        Utils.getScreenShot(Thread.currentThread().getName());

    }
}
